package com.zhuangjie.coupon.controller;

import com.zhaungjie.base.conduit.R;
import com.zhuangjie.base.constant.ModuleSecurityNames;
import com.zhuangjie.coupon.service.CouponOrderService;
import com.zhuangjie.security.annotations.NoAuthentication;
import com.zhuangjie.security.annotations.PublicAPI;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhuangjie
 * @since 2024-02-28
 */
@RestController
@RequestMapping("/coupon-order")
public class CouponOrderController {
    @Autowired
    private CouponOrderService couponOrderService;

    @ApiOperation("创建优惠卷订单")
    @PublicAPI(modules = {ModuleSecurityNames.USER})
    @PostMapping("/create/{productOrderId}")
    public R createCouponOrder(@PathVariable("productOrderId") Long productOrderId) {
        // 返回优惠卷订单支付参数
        return R.require(couponOrderService.createCouponOrder(productOrderId));
    }

    @ApiOperation("支付优惠卷订单")
    @NoAuthentication
    @PostMapping("/payment/{orderId}")
    public R paymentCouponOrder(@PathVariable("orderId") Long orderId) {
        return R.capture(()->couponOrderService.paymentCouponOrder(orderId));
    }

}
